package com.ruoyi.stock.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.stock.domain.WarehouseIn;
import com.ruoyi.stock.domain.WarehouseInInfo;
import com.ruoyi.stock.domain.vo.WarehouseInVo;
import com.ruoyi.stock.mapper.WarehouseInInfoMapper;
import com.ruoyi.stock.mapper.WarehouseInMapper;
import com.ruoyi.stock.service.IWarehouseInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 入库Service业务层处理
 *
 * @author YwaiX
 * @date 2024-10-29
 */
@Service
public class WarehouseInServiceImpl implements IWarehouseInService {
    @Autowired
    private WarehouseInMapper warehouseInMapper;

    @Autowired
    private WarehouseInInfoMapper warehouseInInfoMapper;

    /**
     * 查询入库
     *
     * @param id 入库主键
     * @return 入库
     */
    @Override
    public WarehouseIn selectWarehouseInById(Long id) {
        return warehouseInMapper.selectWarehouseInById(id);
    }

    /**
     * 查询入库列表
     *
     * @param warehouseIn 入库
     * @return 入库
     */
    @Override
    public List<WarehouseInVo> selectWarehouseIns(WarehouseInVo warehouseIn) {
        return warehouseInMapper.selectWarehouseIns(warehouseIn);
    }

    @Override
    public List<WarehouseIn> selectWarehouseInList(WarehouseIn warehouseIn) {
        return warehouseInMapper.selectWarehouseInList(warehouseIn);
    }

    /**
     * 新增入库
     *
     * @param warehouseIn 入库
     * @return 结果
     */
    @Override
    public int insertWarehouseIn(WarehouseIn warehouseIn) {
        return warehouseInMapper.insertWarehouseIn(warehouseIn);
    }

    /**
     * 采购入库
     * @param warehouseIn
     * @return
     */
    @Override
    public void insertWarehouseInPurchase(WarehouseIn warehouseIn) {
        warehouseIn.setCreateTime(DateUtils.getNowDate());
        warehouseInMapper.insertWarehouseIn(warehouseIn);
        for (WarehouseInInfo warehouseInInfo : warehouseIn.getWarehouseInInfoList()){
            warehouseInInfo.setWarehouseInId(warehouseIn.getId());
            warehouseInInfoMapper.insertWarehouseInInfo(warehouseInInfo);
        }
    }

    /**
     * 修改入库
     *
     * @param warehouseIn 入库
     * @return 结果
     */
    @Override
    public int updateWarehouseIn(WarehouseIn warehouseIn) {
        return warehouseInMapper.updateWarehouseIn(warehouseIn);
    }

    /**
     * 批量删除入库
     *
     * @param ids 需要删除的入库主键
     * @return 结果
     */
    @Override
    public int deleteWarehouseInByIds(Long[] ids) {
        return warehouseInMapper.deleteWarehouseInByIds(ids);
    }

    /**
     * 删除入库信息
     *
     * @param id 入库主键
     * @return 结果
     */
    @Override
    public int deleteWarehouseInById(Long id) {
        return warehouseInMapper.deleteWarehouseInById(id);
    }
}
